;------------------------------------------------------------------------------
; itoa.asm
; Utilites for converting integers to ASCII and back.
;
; Cliff Free
; Copyright, 11/2010
;------------------------------------------------------------------------------

extern	_GLOBAL_OFFSET_TABLE_		; The table ld uses as the bse for all
					; our data.


;------------------------------------------------------------------------------
; get_GOT 
;
; Macro which puts the address of the GOT into ebx.  We can use it as the base
; to find our data / variables.
;
; c 11/2010
;------------------------------------------------------------------------------
%macro	get_GOT 0
	call %%getgot
   %%getgot:
   	pop	ebx
	add	ebx, _GLOBAL_OFFSET_TABLE_ + $$ - %%getgot wrt ..gotpc
%endmacro



section .data


section .bss


section .text

;------------------------------------------------------------------------------
; EXPORTED FUNCTIONS
;------------------------------------------------------------------------------
global	int_to_ascii_dec:function
;global	dec_ascii_to_int:function
;global	int_to_ascii_hex:function
;global	hex_ascii_to_int:function


;------------------------------------------------------------------------------
; int_to_ascii_dec
; Function converts integer into ASCII decimal representation
; arg0 - eax - integer to convert .
; returns - address of char[] holding ASCII decimal representation.
; c 11/2010
;------------------------------------------------------------------------------
int_to_ascii_dec:
	push	ebp		; Standard Preamble: sets up stack frame.
	mov	ebp,esp		; Standard Preamble, part 2.
	push	ebx
	push	esi

	get_GOT			; get GOT to use in finding our variables.

	mov	ecx,eax		; save original int.
divloop:
	xor	edx,edx		; Clear edx
	mov	esi, 10
	idiv	esi		; get first base to print
	mov	esi,edx
	add	esi,48		; Add 48 to convert decimal to ASCII rep.
	xor	eax,0		; Are we done yet?
	jnz	divloop

	mov	eax,esi		; Put result into eax for return.
	
	pop	esi		; restore regs...
	mov	ebx,[ebp-4]
	mov	esp,ebp
	pop	ebp
	ret			; ... and return


;------------------------------------------------------------------------------
; dec_ascii_to_int
; Function converts an ASCII representation of decimal to an integer.
; arg0	- eax - address of char[] to convert.
; arg1  - ebx - size of char array.
; returns - address of int[] holding real ints.
; c 11/2010
;------------------------------------------------------------------------------
;dec_ascii_to_int:
;	push	ebp
;	mov	ebp,esp
;	push	ebx

;	get_GOT

;	mov	ecx,[eax]
;	and	ecx,0x0F;


	

	



